{% extends "base_markets.html" %}

{% block mainheading %}{{ block.super }} \ Markets{% endblock %}

{% block leftmenu %}
    {# No menu #}
{% endblock %}

{% block object-tools %}
    <ul class="object-tools">
        <li>
            <a class="addlink" href="/portadmin/market/add/">Add Market</a>
        </li>
    </ul>
{% endblock %}

{% block content %}

    <div id="ParametersLoader" style="display: none;"><img src="{{ MEDIA_URL }}/images/ajaxloading.gif" alt="Loading..." /></div>

    <div>
        <table cellspacing="0">
            <thead>
            <tr>
                <th class="action-checkbox-column" scope="col">
                PK
                </th><th scope="col">
                <select id="StatusId" name="status_id" onchange="JrcLoadMarkets(gPageNr);">
                    <option value="0">Status id</option>
                    <option value="1">approved</option>
                    <option value="2">deleted</option>
                </select>
                </th><th scope="col">
                <select id="AssetId" name="asset_id" onchange="JrcLoadMarkets(gPageNr);">
                    <option value="0">Asset class</option>
                    {% for item in assets %}
                        <option value="{{ item.pk }}">{{ item.name }}</option>
                    {% endfor %}
                </select>
                </th><th scope="col">
                Name
                </th>
                <th>
                Stock exchange
                </th>
                <th>
                Currency
                </th>
                <th>
                Points
                </th>
                <th>
                Price of point
                </th>
                <th>
                Price of contract
                </th>
                <th>
                Start
                </th>
                <th>
                End
                </th>
                <th>
                UTC
                </th><th>
                Decimal places
                </th><th>
                Actions
                </th>
            </tr>
            </thead>
            
            <tbody id="ParametersTbody">
            </tbody>

        </table>
    </div>

<script type="text/javascript">

    var gPageNr = {{ page|default:"1" }};
    var gIsOperationLoaded = true;

    function JrcLoadMarkets(page)
    {
        if( gIsOperationLoaded )
        {
            gIsOperationLoaded = false;
            jQuery("#ParametersLoader").show();
            
            jQuery.ajax({
                url: "/portadmin/" + page + "/getmarkets/"
                , data: "status_id=" + jQuery("#StatusId").val() + "&asset_id=" + jQuery("#AssetId").val()
                , success: function(data){ OnJrcMarketsLoaded(data); }
                , error: function(){ OnJrcMarketsFailed(); }
            });
        }
    }

    function OnJrcMarketsLoaded(data)
    {
        gIsOperationLoaded = true;
        jQuery("#ParametersLoader").hide();
        jQuery("#ParametersTbody").html(data);
    }

    function OnJrcMarketsFailed()
    {
        gIsOperationLoaded = true;
        jQuery("#ParametersLoader").hide();
        jQuery("#ParametersTbody").html("<tr><td colspan='6'>Error loading data!</td></tr>");
    }

</script>

{% endblock %}


{% block js_on_load %}
    {{ block.super }}

    // Loading initial parameters
    JrcLoadMarkets(gPageNr);
    
{% endblock %}
